package com.hex.ds.hdrs.common.sort;

import com.hex.ds.hdrs.common.constant.ErrorCode;
import com.hex.ds.hdrs.common.exception.BizException;
import com.hex.ds.hdrs.period.task.po.PeriodTask;
import lombok.extern.slf4j.Slf4j;

/**
 * 按优先级且资源数顺序,资源数由小到大
 */
@Slf4j
public class SortByPriorityAndResAsc extends SortByStrategy {

    @Override
    public boolean compare(PeriodTask srcTask, PeriodTask targetTask) {
        log.debug("按优先级且资源数顺序,资源数由小到大【SortByPriorityAndResAsc.compare】新增任务【{}】【{}】||比较任务【{}】【{}】",
                srcTask.getTaskCode(), srcTask.getBizDate(), targetTask.getTaskCode(), targetTask.getBizDate());
        try {
            if (srcTask.getPriorityLevel().equals(targetTask.getPriorityLevel())) {
                return srcTask.getResNum() < targetTask.getResNum();
            } else {
                return srcTask.getPriorityLevel() > targetTask.getPriorityLevel();
            }
        } catch (Exception e) {
            log.error("【SortByPriorityAndResAsc.compare】异常:{}", e.getMessage(), e);

            throw new BizException(ErrorCode.ERROR_888004);
        }
    }
}
